<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Vendor styles -->
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<link rel="stylesheet" href="../css/leftnav.css" />
<style type="text/css">
html,body{
	height: 100%;
}
</style>
</head>
<body>
	<!-- 顶部 -->
	<div class="navbar navbar-duomi navbar-static-top" role="navigation" style="height: 10%;">
        <div class="container-fluid">
            <div class="navbar-header">
                <div class="navbar-brand" href="/Admin/index.html" id="logo">宠物医院信息管理系统
                </div>
            </div>
        </div>
	</div>
	
	<div class="container-fluid">
		<div class="row">
			 <div id='leftnav1' class="col-xs-2" style="margin-top: 100px;margin-bottom: 100px;">
			 <!--导航栏  --><script>
	var sf = getCookie('staff');
	if(isNotEmpty(sf)){
		$('#'+sf).siblings("li.panel").hide();
	}

</script>


<ul id="accordion" class="main-nav nav nav-tabs nav-stacked" >
      <li class="active">
              <%-- 全局修改三 : a标签调转 http://localhost/qiantai/index.jsp--%>
              <a href="http://localhost/qiantai/index.jsp"><i class="glyphicon glyphicon-th-large"></i>首页</a>
      </li>

      <li class="panel">
          <a href="#role" class="nav-header collapsed" data-toggle="collapse" data-parent="#accordion">
              <i class="glyphicon glyphicon-cog"></i>科室管理<span class="pull-right glyphicon glyphicon-chevron-down"></span>
          </a>
          <ul id="role" class="nav nav-list collapse secondmenu" style="height: 0px;">
              <li><a href="role.jsp"><i class="glyphicon glyphicon-user"></i>查看科室</a></li>
              <li><a href="role_add.jsp"><i class="glyphicon glyphicon-th-list"></i>增加科室</a></li>
          </ul>
      </li>
      <li class="panel">
          <a href="#staff" class="nav-header collapsed" data-toggle="collapse" data-parent="#accordion">
              <i class="glyphicon glyphicon-cog"></i>医生管理<span class="pull-right glyphicon glyphicon-chevron-down"></span>
          </a>
          <ul id="staff" class="nav nav-list collapse secondmenu" style="height: 0px;">
              <li><a href="staff.jsp"><i class="glyphicon glyphicon-user"></i>查看医生</a></li>
              <li><a href="staff_add.jsp"><i class="glyphicon glyphicon-th-list"></i>增加医生</a></li>
          </ul>
      </li>
      <li class="panel">
          <a href="#user" class="nav-header collapsed" data-toggle="collapse" data-parent="#accordion">
              <i class="glyphicon glyphicon-cog"></i>用户管理<span class="pull-right glyphicon glyphicon-chevron-down"></span>
          </a>
          <ul id="user" class="nav nav-list collapse secondmenu" style="height: 0px;">
              <li><a href="user.jsp"><i class="glyphicon glyphicon-user"></i>查看用户</a></li>
              <li><a href="user_add.jsp"><i class="glyphicon glyphicon-th-list"></i>增加用户</a></li>
          </ul>
      </li>

      <li class="panel" id="role2">
          <a href="#repair" class="nav-header collapsed" data-toggle="collapse" data-parent="#accordion">
              <i class="glyphicon glyphicon-cog"></i>病例管理<span class="pull-right glyphicon glyphicon-chevron-down"></span>
          </a>
          <ul id="repair" class="nav nav-list collapse secondmenu" style="height: 0px;">
              <li><a href="repair.jsp"><i class="glyphicon glyphicon-user"></i>查看病例</a></li>
              <li><a href="repair_add.jsp"><i class="glyphicon glyphicon-th-list"></i>增加病例</a></li>
          </ul>
      </li>
      <li class="panel" id="role3">
          <a href="#complaints" class="nav-header collapsed" data-toggle="collapse" data-parent="#accordion">
              <i class="glyphicon glyphicon-cog"></i>美容管理<span class="pull-right glyphicon glyphicon-chevron-down"></span>
          </a>
          <ul id="complaints" class="nav nav-list collapse secondmenu" style="height: 0px;">
              <li><a href="complaints.jsp"><i class="glyphicon glyphicon-user"></i>查看美容信息</a></li>
              <li><a href="complaints_add.jsp"><i class="glyphicon glyphicon-th-list"></i>增加美容信息</a></li>
          </ul>
      </li>
      <li class="">
          <a href="../index.jsp"><i class="glyphicon glyphicon-th-large"></i>安全退出</a>
      </li>
</ul>
			 </div>
			 
			 <div id='leftnav2' class="col-xs-10">
			 
			 <div class="page-header">
			    <h1>编辑医生信息
			        <small>
			        	<a href="staff.jsp">查看医生信息</a>
			        </small>
			    </h1>
			</div>
			 
			 <form class="form-horizontal" role="form">
				  <div class="form-group">
				    <label for="name" class="col-sm-1 control-label">姓名</label>
				    <div class="col-sm-6">
				      <input type="text" class="form-control" id="name" placeholder="" />
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="sex" class="col-sm-1 control-label">性别</label>
				    <div class="col-sm-6">
				      <input type="text" class="form-control" id="sex" placeholder="" />
				    </div>
				  </div>
	              <div class="form-group">
				    <label for="photo" class="col-sm-1 control-label">照片</label>
				    <div class="col-sm-6">
				      <input type="file" class="form-control" id="photo" placeholder="" />
				    </div>
				  </div>
				  <div class="form-group">
					  <div class="img_thumbs col-sm-6 col-sm-offset-1">
		                 	<img src="" id='photo_preview' />
	         	 	  </div>
	         	  </div>
				  <div class="form-group">
						<label for="username" class="col-sm-1 control-label">职称</label>
						<div class="col-sm-6">
				      <input type="text" class="form-control" id="username" placeholder="" />
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="password" class="col-sm-1 control-label">权限</label>
				    <div class="col-sm-6">
				      <input type="text" class="form-control" id="password" placeholder="" />
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="roleId" class="col-sm-1 control-label">主治专业</label>
				    <div class="col-sm-6">
				      <select class="form-control" id="roleId"></select>
				    </div>
				  </div>	 
				  <div class="form-group">
				    <div class="col-sm-offset-2 col-sm-10">
				      <button id='edit_staff' type="submit" class="btn btn-primary col-sm-1">更新</button>
				    </div>
				  </div>
				</form>
			 </div>
		</div> 
	</div>
  <script src="../js/jquery-1.11.3.min.js"></script>
  <script src="../js/bootstrap.min.js"></script>
  <script src="../js/public_fuc.js"></script> 
   <script type="text/javascript">
       $(function() {
        $("#leftnav").load("pubnav.html");
        $('#name').val(get_param('name'));
        $('#sex').val(get_param('sex'));
        $('#photo_preview').attr('src',get_param('photo'));
        
        //绑定input = file 监听
        $("#photo").change(function(){
 		    readURL(this,$("#photo_preview"));
 		});
 		
        $('#username').val(get_param('username'));
        $('#password').val(get_param('password'));
		$.get("../api/role/list",function(data){
			var html = '';
			if (data.code== 0) {
				var arr = data.data;
				for (var i = 0,len = arr.length; i < len; i++) {
					var obj = arr[i];
					html += '<option value="'+obj.id+'">'+obj.name+'</option>';
				}
			} else {
				html += '<option value="-1">请先添加权限</option>';
			}
			
			document.getElementById('roleId').innerHTML = html;
			$('#roleId').val(get_param('roleId'));
		});
 		
		
		
		editStaff();
      });
      
		//预览
     	function readURL(input,show) {
		if (input.files && input.files[0]) {
		    var reader = new FileReader();
	           reader.onload = function (e) {
		          show.attr('src', e.target.result);
		        }
		        reader.readAsDataURL(input.files[0]);
		 	}
		}
      
			 //编辑Staff
      var editStaff = function(){
      	$('#edit_staff').click(function(){
      		var formData = new FormData();
			formData.append('name',document.getElementById('name').value);
			formData.append('sex',document.getElementById('sex').value);
			var photoFile = document.getElementById('photo').files[0];
			if (isEmpty(photoFile)) {
	      		formData.append("photo", $('#photo_preview').attr('src'));
			} else {
	      		formData.append("photo", photoFile);
			}
			formData.append('username',document.getElementById('username').value);
			formData.append('password',document.getElementById('password').value);
			formData.append('roleId',document.getElementById('roleId').value);
			formData.append('id',get_param('id'));
			$.ajax({
              url: '../api/staff/update',
              type: 'POST',
              data: formData,
              cache: false,
              dataType:'json',
              contentType: false,
              processData: false,
              success: function (data) {
                  if(data.code=='0'){
                	 window.location.href = 'staff.jsp';
                  }
              }
             });
             return false;
    	  });
      }
      
    </script>    
 </body> 
 </body>
</html>